package com.kyh.util;

public class StringBoUtil {
	public static String lowerFirst(String str) {
		
		char [] chars = str.toCharArray();
		if (chars[0] >= 'A' && chars[0] <= 'Z') {
			chars[0] += 32;
		}
		
		return String.valueOf(chars);
	}

	/**
	 * 替换下划线为驼峰
	 * @param str
	 */
	public static String replaceUnderLineAndUpperCase(String str) {
		StringBuffer sb = new StringBuffer();
		sb.append(str);
		
		// 获取下划线所在
		int count = sb.indexOf("_");
		while (count != 0) {
			int num = sb.indexOf("_", count);
			count = num + 1;
			if (num != -1) {
				char ss = sb.charAt(count);
				char ia = (char) (ss - 32);
				sb.replace(count, count + 1, ia + "");
			}
		}
		String result = sb.toString().replaceAll("_", "");
		return result;
	}
	/**
	 * 处理字符串每多少个加换行符(insert)
	 * 处理字符串每多少个换省略号(substring)
	 * @param str 字符串
	 * @param line 字符串每line个字符，加一个换行符
	 * @param subInt 字符串长度超过subInt，后面的字符串就变成省略号
	 * @return 处理好的字符串
	 * @author lwj
	 */
	public static String handleStrLineAndSub(String str,Integer line,Integer subInt) {
		StringBuffer bufStr = new StringBuffer(str);
		for (int i = 0; i < bufStr.length(); i++) {
			if(i%line==0&&i!=0) {
				bufStr.insert(i,"\n");
			}
		}
		String subStr = "";
		if(bufStr.length()>subInt) {
			subStr = bufStr.substring(0, subInt) + "...";
		}else {
			subStr = bufStr.toString();
		}
		return subStr;
	}
	
}
